import { RouterBase } from "./RouterBase";
/**
 * 默认路由
 */
export class Router extends RouterBase {
  /**
   * 生成
   */
  build() {
    const route = this.packageProperty();
    if (this._children) {
      // 编译实体
      const entityGenerator = (entity) => {
        let entities = [];
        if (typeof entity.build === 'function') {
          entities.push(...entityGenerator(entity.build()));
        } else if (Array.isArray(entity)) {
          entity.forEach(child => {
            entities.push(...entityGenerator(child));
          });
        } else {
          entities.push(entity);
        }
        return entities;
      }
      route.children = entityGenerator(this._children);
    }
    return route;
  }
}
